<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    
	
	<title>_出库管理</title>
	<script type="text/javascript">
	
        $(function() {
		    $("#queryForm").validate(); 
			$("#_fromDate").datepicker({ format : 'yyyy-mm-dd' });
			$("#_toDate").datepicker({ format : 'yyyy-mm-dd' });
       });
	  
        var filterParam = {};
		var datatable_content;
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
			   "bAutoWidth":false,
	           "sAjaxSource":'${ctx}/outstorageBill/page',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	{"mData": null},
	             	 {"mData": "customer.customerName",
	             		"render":function(data,type,full){
	             		 return full.customer ? full.customer.customerName : '';
	             	 }},
	             	 {"mData": "billType"},
	             	 {"mData": "billCode"},
	             	 {"mData": "aboutCode"},
	             	 {"mData": "warehouseOut"},
	             	 {"mData": "warehouseIn"},
	             	 {"mData": "boxNum"},
	             	 {"mData": "skuNum"},
	             	 {"mData": "goodsNum"},
	             	 {"mData": "createTime"},
	             	 {"mData": "status"},
	             	 {"mData": "creater.realname"},
	             	 {"mData": null},
	             ],
	             
	             "aoColumnDefs":[
	             	{"aTargets": [2],
		              "mRender": function (data, display, row) {
		              		return data == "allot" ? "<font color=red>调拨出库</font>" : 
		              		       data == "sale"? "<font color=blue>销售出库</font>" :
		              		       data == "return"? "<font color=green>返仓出库</font>" :
		              		       data == "bad_return"? "<font color=gray>残次返厂</font>" :
		              		       "";
			           }
		            },
	             	{"aTargets": [5],
		              "mRender": function (data, display, row) {
		              		return data ? data.groupName:"";
			           }
		            },
	             	{"aTargets": [6],
		              "mRender": function (data, display, row) {
		              		return data ? data.groupName:"";
			           }
		            },
	             	{"aTargets": [10],
		              "mRender": function (data, display, row) {
		              		return data ? new Date(row.createTime.time).Format("yyyy-MM-dd") : "";
			           }
		            },
	             	{"aTargets": [11],
		              "mRender": function (data, display, row) {
		              		return data == "1" ? "创建出库单" : 
		              		       data == "2"? "领取拣货任务" :
		              		       data == "3"? "完成拣货" :
		              		       data == "4"? "领取发货任务" :
		              		       data == "5"? "完成发货" :
		              		       data == "6"? "收货确认" :
		              		       "";
			           }
		            },
	             	{"aTargets": [13],
		              "mRender": function (data, display, row) {
						  return "<a href=\"${ctx}/outstorageBill/v2_toOutstorageBillDetailPage/"+row.billCode+"\" data-toggle=\"modal\" class=\"btn btn-primary\" >详情</a>";
			           }
		            },
	             ],
			});
		}
		
		function filter(item){
			filterParam[item.name] = item;
		}
		function callback(sSource, aoData, fnCallback ) {
		   	var formParam = $("#queryForm").serializeArray();
			for(var n in filterParam){
				formParam.push(filterParam[n]);
			}
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData.concat(formParam)),
		       "success": function (data) {
				   fnCallback(data);
                   //关闭遮罩
				   closeBg();
			   }
		   });
		}
		
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
		}
		
		function query(){
			if($("#queryForm").valid()){
				if (datatable_content) {
					datatable_content.fnDestroy();
				}
				//开启遮罩
				showBg();
				initTable();
			}
		}
       //删除入库单
       function deleteBill(billId){
          return;
          $.ajax({
			   type : 'post',
				url : '${ctx}/instorageBill/ajaxDelete',
				data : {
					billId:billId
				},
				dataType : 'json',
				success : function(data) {
				   if(data==true){
				      $("#queryForm").submit();
				   }else{
				      alert("网络繁忙，请稍后重试...");
				   }	
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
				}
			}); 
          
       }
 		
    </script>
</head>

<body>
<div id="fullbg"></div>
<div id="dialog">
	<div>
		<img src="${ctx }/static/022.gif"></img>
	</div>
</div>
<section class="content">
<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-edit"></i>
					<h3 class="box-title">条件查询</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<form class="form-search" id="queryForm" method="post">
	<div class="form-group row">
		    <div class="col-sm-3">
<div class="input-group col-sm-12">
<span class="input-group-text"> 商家： </span>
	 <select  name="_EQ_customerCode"  id="_customerCode" value="${param._EQ_customerCode}"  class="form-control" onchange="ajaxAreaGroup(this,'_warehouseOutCode');">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${param._EQ_customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
					</div>
					</div>
					 <div class="col-sm-3">
<div class="input-group col-sm-12">
<span class="input-group-text"> 出货仓：  </span>
 <select  name="_EQ_warehouseOutCode"  id="_warehouseOutCode"  class="form-control" >
				     <option value=""></option>  
				     <c:forEach items="${warehouseList}" var="warehouse">
				       <option value="${warehouse.groupCode}" 
				       <c:if test="${param._EQ_warehouseOutCode eq warehouse.groupCode }">selected=selected</c:if>
				       >${warehouse.groupName}</option>
				     </c:forEach>
				</select>
					</div>
					</div>
					 <div class="col-sm-3">
<div class="input-group col-sm-12">
<span class="input-group-text"> 进货仓：  </span>
<select  name="_EQ_warehouseInCode"  id="_warehouseInCode" class="form-control" >
				     <option value=""></option>  
				     <c:forEach items="${warehouseList1}" var="warehouse">
				       <option value="${warehouse.groupCode}" 
				       <c:if test="${param._EQ_warehouseInCode eq warehouse.groupCode }">selected=selected</c:if>
				       >${warehouse.groupName}</option>
				     </c:forEach>
				</select>
					</div>
					</div>
					 <div class="col-sm-3">
<div class="input-group col-sm-12">
<span class="input-group-text"> 类型：  </span>
  <select  name="_EQ_billType"  id="_billType" class="form-control">
					<option value="" <c:if test="${param._EQ_billType eq ''}">selected=selected</c:if> ></option>
				    <option value="allot" <c:if test="${param._EQ_billType eq 'allot'}">selected=selected</c:if> >调拨出库</option>
				    <option value="sale" <c:if test="${param._EQ_billType eq 'sale'}">selected=selected</c:if> >销售出库</option>
				    <option value="return" <c:if test="${param._EQ_billType eq 'return'}">selected=selected</c:if> >销售出库</option>
				</select>
					</div>
					</div>
					</div>
					
					<div class="form-group row">
		    <div class="col-sm-3">
<div class="input-group col-sm-12">
<span class="input-group-text"> 状态： </span>
<select  name="_EQ_status"  id="_status"   class="form-control">
					<option value="" <c:if test="${param._EQ_status eq ''}">selected=selected</c:if> ></option>
				    <option value="1" <c:if test="${param._EQ_status eq '1'}">selected=selected</c:if> >创建出库单</option>
				    <option value="2" <c:if test="${param._EQ_status eq '2'}">selected=selected</c:if> >领取拣货任务</option>
				    <option value="3" <c:if test="${param._EQ_status eq '3'}">selected=selected</c:if> >完成拣货</option>
				    <option value="4" <c:if test="${param._EQ_status eq '4'}">selected=selected</c:if> >领取发货任务</option>
				    <option value="5" <c:if test="${param._EQ_status eq '5'}">selected=selected</c:if> >完成发货</option>
				    <option value="6" <c:if test="${param._EQ_status eq '6'}">selected=selected</c:if> >确认收货</option>
				</select>
					</div>
					</div>
					 <div class="col-sm-3">
<div class="input-group col-sm-12">
<span class="input-group-text"> 创建日期：  </span>
 <input type="text" name="_GTE_createTime" id="_fromDate"  class=" form-control" value="${param._GTE_createTime}"> 
					</div>
					</div>
					 <div class="col-sm-3">
<div class="input-group col-sm-12">
<span class="input-group-text"> 至：  </span>
 <input type="text" name="_LT_createTime" id="_toDate" class=" form-control" value="${param._LT_createTime}"> 
					</div>
					</div>
				</div>
			
			<div class="form-group row">
			 <div class="col-sm-12">
                <button type="button" onclick="query()" class="btn btn-primary" style="margin-left: 10px;">搜索</button>
			    <a   href="${ctx}/outstorageBill/v2_toCreateBill/allot"  class="btn btn-info" >调拨出库</a>
			    <a   href="${ctx}/outstorageBill/v2_toCreateBill/sale"   class="btn btn-info" onclick="">销售出库</a>
			    <a   href="${ctx}/outstorageBill/v2_toCreateBill/return" class="btn btn-info" >返仓出库</a>
				<a   href="${ctx}/outstorageBill/v2_toCreateBill/bad_return" class="btn btn-info" >残次品返仓出库</a>	
					</div>
		</div>
	   </form>
	</div>
	</div>
	</div>
	</div>
	
	
	<div class="row">
		<div class="col-md-12">

			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th style="width: 10px;">序号</th>
		    <th style="width: 100px;">商家</th>
		    <th style="width: 80px;">类型</th>
		    <th style="width: 180px;">单号</th>
		    <th style="width: 80px;">相关单号</th>
		    <th style="width: 80px;">出货仓</th>
		    <th style="width: 80px;">进货仓</th>
			<th style="width: 80px;">箱子数量</th>
			<th style="width: 80px;">SKU数量</th>
			<th style="width: 80px;">商品数量</th>
			<th style="width: 150px;">登记时间</th>
			<th style="width: 80px;">状态</th>
			<th style="width: 100px;">创建人</th>
			<th style="width: 150px;">管理</th>
		</tr></thead>
		<tbody>
		</tbody>
	</table>
	
</div>
</div>
</div>
</div>
</section>	
</body>
</html>
